"use strict";
var WatchLaterManager;

/**
 * The Watch Later Manager is a utility for adding videos to the "watch later"
 * playlist.
 *
 * @constructor
 */
WatchLaterManager = function () {
    var oauth;

    /**
     * Constructor.
     */
    (function () {
        oauth = new OAuth2();
    }());

    /**
     * Adds the specified video to the "watch later" playlist.
     *
     * @param {String} videoID ID of the video to add to the "watch later"
     *        playlist.
     * @param {Function} callback Callback to execute if the operation was
     *        successful.
     * @param {Function} errCallback Callback to execute if the operation
     *        fails.
     */
    this.add = function (videoID, callback, errCallback) {
        var body, url;
        body = '<?xml version="1.0" encoding="UTF-8"?>\n' +
                '<entry xmlns="http://www.w3.org/2005/Atom"\n' +
                '    xmlns:yt="http://gdata.youtube.com/schemas/2007">\n' +
                '  <id>' + videoID + '</id>\n' +
                '</entry>';
        url = 'https://gdata.youtube.com/feeds/api/users/default/watch_later';
        try {
            oauth.post(url, {}, 'application/atom+xml', body, callback,
                    errCallback);
        } catch (e) {
            // OAuth is not set up yet
            chrome.tabs.create({
                url: chrome.extension.getURL('install.html')
            });
        }
    };
};
